package com.jgzx.domain;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jackesy
 * @className: TreeNode
 * @description: 树节点
 * @create 2021/2/2 19:54
 **/
@ApiModel(value = "树节点对象")
@Data
public class TreeNode<T extends TreeNode<?>>{

    @ApiModelProperty(value = "树节点ID", required = true)
    @JsonSerialize(using = ToStringSerializer.class)
    private Object id;

    @ApiModelProperty(value = "上级节点ID", required = true)
    @JsonSerialize(using = ToStringSerializer.class)
    private Object p_id;

    @ApiModelProperty(value = "是否是叶节点：0-非叶节点，1-叶节点", required = true)
    private Boolean leaf_flag;

    @ApiModelProperty(value = "孩子们", required = true)
    private List<T> children = new ArrayList<>();

    public void add(T t) {
        children.add(t);
    }

    public List<T> getChildren() {
        return children;
    }

    public void setChildren(List<T> children) {
        this.children = children;
    }
}
